package middleware

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func Cors() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Header("Access-Control-Allow-Origin","*")
		c.Header("Access-Control-Allow-Headers","Origin,X-Requested-with,Content-type,Accept")
		c.Header("Access-Control-Allow-Methods","GET,OPTIONS,POST,PUT,DELETE")
		c.Set("content-type","application/json")

		method:=c.Request.Method
		if method=="OPTIONS" {
			c.String(http.StatusOK,"ok")
		}

		c.Next()
	}
}
